package com.pktechan.manage.service.impl;

import com.pktechan.manage.base.BaseMapper;
import com.pktechan.manage.base.BaseServiceImpl;
import com.pktechan.manage.dao.ProductMapper;
import com.pktechan.manage.entity.ProductBaseInfo;
import com.pktechan.manage.exception.CustomException;
import com.pktechan.manage.service.ProductService;
import com.pktechan.manage.utils.FastDfsHttpUtil;
import com.pktechan.manage.utils.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @program: cloudfloating
 * @description: 产品相关功能服务层实现
 * @author: qx.zhang
 * @create: 2021-03-05 11:48
 **/
@Service("productService")
public class ProductServiceImpl extends BaseServiceImpl<ProductBaseInfo> implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    /**
     * 由业务类实现
     *
     * @return
     */
    @Override
    public BaseMapper<ProductBaseInfo> getBaseMapper() {
        return productMapper;
    }

    /**
     * 根据id查询产品细信息
     * @param id
     * @return
     */
    @Override
    public ProductBaseInfo getById(Integer id) {
        ProductBaseInfo productBaseInfo = (ProductBaseInfo) productMapper.getById(id);
        return productBaseInfo;
    }

    /**
     *  产品列表
     * @param productBaseInfo
     * @return
     */
    @Override
    public List<ProductBaseInfo> getList(ProductBaseInfo productBaseInfo) {
        List<ProductBaseInfo> productBaseInfoList = productMapper.getList(productBaseInfo);
        return productBaseInfoList;
    }

    /**
     * 修改产品置顶
     * @param productId
     */
    @Override
    public void updateProductTop(Integer productId) {
        //查询产品排序最大的一条
        ProductBaseInfo productMaxSortOrder = productMapper.getProductMaxSortOrder();
        //修改产品排序
        ProductBaseInfo productBaseInfo = new ProductBaseInfo();
        productBaseInfo.setId(productId);
        productBaseInfo.setSortOrder(productMaxSortOrder.getSortOrder()+1);
        productMapper.update(productBaseInfo);
    }
}
